package flextv.main.logic.download {

import flash.events.TimerEvent;
import flash.filesystem.File;
import flash.utils.Timer;

import flextv.core.download.IDownloadable;
import flextv.core.logic.Logger;
import flextv.main.logic.AirUtil;

import mx.logging.ILogger;

public class MockDownloadService implements IDownloadService {
	
	private static const LOG: ILogger = Logger.getLog(MockDownloadService);
	
	public function MockDownloadService() {
	}
	
	public function download(item: IDownloadable, target: File, fnResult: Function): void {
		LOG.info("download(item="+item+"; target="+target+")");
		
		var t: Timer = new Timer(10, 20);
		t.addEventListener(TimerEvent.TIMER, function(event: TimerEvent): void {
			item.downloaded += 5;
			
			if(item.downloaded >= 10 && fnResult != null) {
				fnResult(); // indicate flvUri is ready
			}
			
			if(item.downloaded == 100) {
				copyDummyFile(target);
			}
		});
		t.start();
	}
	
	private static const DUMMY: File = AirUtil.resolveFlvFile("dummy_file");
	private static function copyDummyFile(target: File): void {
		DUMMY.copyToAsync(target, true);
	}
}
}